$(function() {
	var staffId = $.cookie("staffid");
	var style_id = $.cookie('jobsId');
	var json = eval(getwebdata(style_id,'1','sel_trainning',2));
	var kspxsp_num = eval(getwebdata(staffId,"1","get_kspx_num",2))[0].kspxsp_num;
	var str = '<ul>';
	for (var i = 0; i <json.length; i++) {
		if(json[i].sectionID == 1){
			str += '<div class="div_cous" style="float: left;width:800px">继续教育</div>';
		}else if(json[i].sectionID == 29){
			str += '<div class="div_cous" style="float: left;width:800px">安全生产管理</div>';
		}else if(json[i].sectionID == 48){
			str += '<div class="div_cous" style="float: left;width:800px">法律法规</div>';
		}else if(json[i].sectionID == 73){
			str += '<div class="div_cous" style="float: left;width:800px">安全生产技术</div>';
		}
		str +='<li id='+json[i].sectionID+'>';
		str +='<h4 class="h4_y"><label>'+(i+1)+'</label></h4>';
		str +='<h4 class="h4_c" style="color:#56ABE4">时长:'+json[i].classTime+'</h4>';
		if(json[i].sectionID <= kspxsp_num){
			str +='<h4 class="h4_c" style="color:#56ABE4;">已完成</h4>';
		}else{
			str +='<h4 class="h4_c" style="color:red;">点击培训</h4>';
		}
		str +='</li>'
	};
	str += '</ul>';
	$("#practice").append(str);
	var ks_messages = eval(getwebdata(staffId, "1", "sql_ksmessage", 2));
	var is_pay = ks_messages[0].is_pay;
	var s_time = ks_messages[0].startTime.substring(0,10);
	var e_time = ks_messages[0].endTime.substring(0,10);
	var date = eval(getwebdata('','1','sql_time',2))[0].time.substring(0,10);
	$("#practice").find('li').each(function(index, el) {
		$(this).click(function(event) {
			if (is_pay == true) {
				if(date < s_time){
					alert("未到培训时间,培训时间为"+s_time+"至"+e_time+"");
				}else if(date > e_time){
					alert("已超过培训时间！结束培训时间为"+e_time+"");
				}else if(kspxsp_num == 0 && $(this).prop("id") == json[0].sectionID){
		            $.cookie('sectionID', index, { exprise: 1 });
					window.location.href = "../../indInfo/kspx/kspx.html";
					getwebdata($(this).prop('id'),'1',"readnumupdate",2);
					getwebdata($.cookie("staffid")+"###"+$(this).prop('id'),'1',"i_jl",2);
					getwebdata($.cookie("staffid"),'1',"i_date_jl",2);
		        }else if($(this).prop("id") == (kspxsp_num+1)){
					$.cookie('sectionID', index, { exprise: 1 });
					window.location.href = "../../indInfo/kspx/kspx.html";
					getwebdata($(this).prop('id'),'1',"readnumupdate",2);
					getwebdata($.cookie("staffid")+"###"+$(this).prop('id'),'1',"i_jl",2);
					//if((kspxsp_num+1) == json[json.length-1].sectionID){
					//	getwebdata($.cookie("staffid"),'1',"i_date_e_jl",2);
					//}
		        }else if((parseInt($(this).prop("id"))) <= kspxsp_num ){
					alert("您已完成该课时，请查看其它未看完的视频");
		        }else if($(this).prop("id") > (kspxsp_num+1)){
	        		alert("前面的教程中存在未看完的视频！");
				}
			}else{
		    	alert("您尚未缴费！");
		    }
		});
	});
})